package com.example.demo.service.mq.rabbitmq;

import com.cclub.inteface.model.messageTemplateBO;
import com.example.demo.config.MessageConfig;
import com.example.demo.service.aliyun.message.messageTools;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sun.istack.internal.NotNull;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import com.example.demo.constant.mqConstant;

@Component
@RequiredArgsConstructor
public class WorkReceiveListener {

    @NonNull
    private messageTools messageTools;

    @NotNull
    private ObjectMapper objectMapper;

    @NotNull
    private MessageConfig messageConfig;

    @RabbitListener(queues = mqConstant.shortMessageMqName)
    public void receive(String msg) throws JsonProcessingException {
        messageTemplateBO bo = objectMapper.readValue(msg,messageTemplateBO.class);
        messageTools.sendCode(bo.getTelephone(),messageConfig.getTemplateConfig().get(bo.getTemplateCode()),bo.getTemplateContent());
    }
}
